1 Package loading

Here we show a report with plots to visualize the output of CloneTracer for sample A.6

# set global chunk settings
knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)

library(tidyverse)
library(Seurat)
library(ComplexHeatmap)
library(reticulate)
pd <- import("pandas")
library(circlize)
library(patchwork)
library(DiagrammeRsvg)
library(DiagrammeR)
library(qpdf)
library(rsvg)
library(DiagrammeRsvg)
source("funct_clonal_analysis.R")

pat <- "A.6"

2 Clonal analysis

Trees selected by CloneTracer are stored in trees_clonetracer.pdf file. The title indicates the tree index which is necessary to identify the tree in the ELBO plot (see below).

# load pickle object
pickle <- pd$read_pickle(paste0("../output/",pat,".pickle"))

# get tree with highest evidence
tree_list <- plot_trees(pickle, clone_cols = F)

# save trees as pdf 
export_trees(tree_list, h = 350, w = 200, outdir = paste0("plots_", pat))

xfun::embed_file("plots_A.6/trees_clonetracer.pdf")

Download trees_clonetracer.pdf


2.1 ELBO plots

2.1.1 All trees

Here I plot the ELBO for the last iteration of the heuristic search. Clearly 3 trees have much higher evidence than the rest.


print_elbo(pickle, first_iter = 200, max_elbo = "22000")


2.1.2 Selected trees

We can zoom in the 3 trees selected by CloneTracer. They have very similar ELBO values. This occurs often when the evidence for different trees is similar. In these cases we always select the simplest tree, this is the clonal hierarchy with lower number of nodes.


print_elbo(pickle, first_iter = 200, trees = pickle$tree_indices)


2.2 Clonal hierarchy

We therefore select the tree with mt:3019G>C and RAD21 merged in one single clone.

sel_tree_ind <- "2"

# make tree
sel_tree <- plot_trees(pickle, tree = sel_tree_ind)

render_graph(sel_tree$tree) %>% export_svg() %>% charToRaw() %>% 
    rsvg_png("plots_A.6/selected_tree.png",
             width = 600, height = 950)

render_graph(sel_tree$tree) 

2.3 Heatmaps

Here we show a heatmap with the VAF of the mutations in single cells as well as the clonal probabilities inferred by CloneTracer. Celltypes of interest can be added as an Annotation column. A seurat can be provided with celltypes as metadata column.

2.3.1 Clonal probabilities

We can show the clone posterior probabilities of each single cell

# load Seurat object
seurat <- subset(readRDS(url("https://figshare.com/ndownloader/files/36434613?private_link=717cb824ed6e13de2bc6")),
                 patient == "A.6") 

# add simplified celltype labels (only needed for this particular object)
seurat <- add_simple_ct(seurat)
seurat$ct <- ifelse(seurat$ct %in% c("T cells", "NK cells", "B cells"), "T & B cells", "Myeloid cells")

# make sure cell_barcodes are the same between seurat and pickle objects
seurat <- RenameCells(seurat, new.names = gsub("(^.+-1).+", "\\1", colnames(seurat)))

heat_clones <- make_heatmap(pickle, 
                        seurat = seurat, 
                        tree = "2",
                        pat = pat,
                        celltype = T, 
                        ct_column = "ct",
                        prob_type = "clones",
                        middle_point = 0.5,
                        clust_rows = T)

draw(heat_clones$plot, annotation_legend_list = heat_clones$legend, merge_legend = TRUE)


2.3.2 Cancer probability

It is also useful to visualize the cancer probabilities computed as 1-posterior probability of being healthy

heat_cancer <- make_heatmap(pickle, 
                        seurat = seurat, 
                        tree = "2",
                        pat = pat,
                        celltype = T, 
                        ct_column = "ct",
                        prob_type = "cancer",
                        middle_point = 0.5,
                        clust_rows = T)

draw(heat_cancer$plot, annotation_legend_list = heat_cancer$legend, merge_legend = TRUE)


2.3.3 Coverage

To get a better understanding of the clonal probabilities is also useful to look at the total coverage on the site.

heat_cvg <- make_heatmap(pickle, 
                        seurat = seurat, 
                        tree = "2",
                        pat = pat,
                        celltype = T, 
                        ct_column = "ct",
                        prob_type = "clones",
                        cvg = T, 
                        cvg_max = 10,
                        middle_point = 0.5,
                        clust_rows = T)

draw(heat_cvg$plot, annotation_legend_list = heat_cvg$legend, merge_legend = TRUE)


2.4 UMAPs

We can visualize the posterior probabilities in a dimensionality reduction plot (UMAP, t-SNE, PCA). It should be contained in a Seurat object

2.4.1 Cancer probabilities

umap_leuk <- umap_leuk(pickle, seurat, tree = sel_tree_ind, reduction = "umap")

umap_leuk


2.4.2 Clones

If we want to visualize the clonal assignments the easiest is to select a posterior probability threshold for the discrete assignments of cells to clones. In our manuscript we use 0.8.

umap_clones <- umap_clones(pickle, seurat, tree = "2", reduction = "umap", post_thr = 0.8)

umap_clones


3 Add metadata to Seurat

We can add the cancer and clonal probabilities as well as the discrete assignments as metadata columns to a Seurat object

# add clonal information to Seurat
seurat <- add_meta(seurat, pickle, tree = "2")